<?php
/**
 * Created by PhpStorm.
 * User: Zjz
 * Date: 2019/3/14
 * Time: 16:17
 */
chdir('./img');

//$db = mysqli_connect('localhost','root', 'root','product','3306');
//$sql = 'SELECT id,cover FROM product';
//$res = mysqli_fetch_all(mysqli_query($db,$sql));
//// 下载图片
////$img_list = array_map(function ($v){
////    $path = substr($v[0],9);
////    $dir = explode('/',$path);
////    $file_name = __DIR__.'/img/'.$dir[0].'/'.$dir[1];
////    if (!is_file($file_name) || filesize($file_name) == 0){
////        $img = file_get_contents('http://www.lcjj1688.com/Uploads/'.$v[0]);
////        !is_dir(__DIR__.'/img/'.$dir[0]) && mkdir(__DIR__.'/img/'.$dir[0]);
////        $img_file = fopen(__DIR__.'/img/'.$dir[0].'/'.$dir[1],'w+');
////        fwrite($img_file,$img);
////        fclose($img_file);
////    }
////    return $path;
////    },$res);
//$img_list = [];
//foreach ($res as $k => $v){
//    $img_list[$v[1]] = intval($v[0]);
//}
////var_dump($res);
//var_dump($img_list);
//$fi = fopen('./data.db','w+');
//fwrite($fi,serialize($img_list));
//fclose($fi);
//mysqli_close($db);
//exit(0);

$dir_list = glob('*');
$img_list = array();
foreach ($dir_list as $v){
    chdir('./'.$v);
    $img_list[$v] = glob('*');
    chdir('../');
}
$img_list = serialize($img_list);
chdir('../');
$f = fopen('./img_list.db','w+');
fwrite($f, $img_list);
fclose($f);
echo 'Successfully to index File !';
